from typing_extensions import get_origin
from manimlib import *
from numpy import angle, square
import numpy as np

class Test(Scene):
    #75cfb8
    #浅绿
    #bbdfc8
    #浅黄
    #f0e5d8
    #深黄
    #ffc478
    config.background_color = WHITE
    def construct(self):
        axes = Axes(
            x_range=[0, 3, 1],
            y_range=[0, 3, 1],
            x_length=6,
            y_length=6,
            axis_config={
                'stroke_width':4,
                "color": BLACK,
                'tip_height':1.1,
                },
            # tips=False,
        )
        self.add(axes)
        y=2
        top=(np.sqrt(5-y*y)+2*y)/5*2

        q=Point().move_to(axes.c2p(0,y))
        r=Point().move_to(axes.c2p(np.sqrt(5-y*y),0))
        p=Point().move_to(axes.c2p((np.sqrt(5-y*y)+2*y)/5,(np.sqrt(5-y*y)+2*y)/5*2))
        o=Point().move_to(axes.c2p(0,0))
        t_p=Tex('P',color=BLACK).next_to(p,UP)
        self.add(Tex('Q',color=BLACK).next_to(q,LEFT),Tex('R',color=BLACK).next_to(r,DOWN),Tex('O',color=BLACK).next_to(o,LEFT),t_p)

        op=Line(o.get_center(),p.get_center(),color=BLACK)
        angle1=Angle(Line(p.get_center(),q.get_center()),Line(p.get_center(),r.get_center()),color=BLACK,elbow=True)
        angle_o=Angle(Line(o.get_center(),r.get_center()),op,color='#75cfb8')
        angle_q=Angle(Line(q.get_center(),r.get_center()),Line(q.get_center(),p.get_center()),color='#75cfb8')
        t1=Tex(r'\alpha',color=BLACK).next_to(angle_o,UR,buff=0)
        t2=Tex(r'\alpha',color=BLACK).next_to(angle_q,RIGHT,buff=0.1)

        
        m=Point().move_to(axes.c2p(0,top))
        n=Point().move_to(axes.c2p(np.sqrt(5-y*y),top))
        # 2
        a1=Angle(Line(r.get_center(),q.get_center()),Line(r.get_center(),o.get_center()),color='#75cfb8')
        a2=Angle(Line(q.get_center(),r.get_center()),Line(q.get_center(),p.get_center()),color='#75cfb8')
        self.add(a1,a2,Tex(r'\theta',color=BLACK).next_to(a1,LEFT,buff=0.1),Tex(r'\alpha',color=BLACK).next_to(a2,RIGHT,buff=0.1))

        self.add(Polygon(q.get_center(),r.get_center(),p.get_center()),angle1)
        self.wait(0.03)
        self.add(angle_q,angle_o,op,t2,t1)

        self.wait(0.03)
        self.remove(angle_o,t1,op)
        self.add(Line(m.get_center(),n.get_center(),color=BLACK),Line(r.get_center(),n.get_center(),color=BLACK))
        angle_r=Angle(Line(r.get_center(),q.get_center()),Line(r.get_center(),o.get_center()),color='#75cfb8')
        angle_rr=Angle(Line(r.get_center(),n.get_center()),Line(r.get_center(),p.get_center()),color='#75cfb8')
        angle_pp=Angle(Line(p.get_center(),m.get_center()),Line(p.get_center(),q.get_center()),color='#75cfb8')
        self.add(angle_r,angle_rr,angle_pp)
        self.add(Tex(r'\theta',color=BLACK).next_to(angle_r,LEFT,buff=0.1),Tex(r'\alpha-\theta',color=BLACK).next_to(angle_rr,RIGHT,buff=0.1),Tex(r'\alpha-\theta',color=BLACK).next_to(angle_pp,LEFT,buff=0.2).shift(DOWN*0.05))
        self.add(Angle(Line(m.get_center(),o.get_center()),Line(m.get_center(),n.get_center()),color=BLACK,elbow=True),Angle(Line(n.get_center(),m.get_center()),Line(n.get_center(),r.get_center()),color=BLACK,elbow=True))
        self.add(Tex('1',color='#75cfb8').next_to(o,UR*5),Tex('T',color=BLACK).next_to(n,UR))
        t_p.become(Tex('P(x,y)',color=BLACK).next_to(p,UP))

        
        self.wait(0.03)